<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class upload extends CI_Controller {

	public $_upload_image_dir = 'data/upload/';
	/*private $_upload_image_dir = 'data/images/';*/
	
	private $_image_exts = 'jpg|jpeg|png|gif|bmp';
	
	private $_images_exts = array('png', 'gif', 'jpg', 'jpeg', 'bmp');

	public function __construct()
	{
		parent::__construct();

		$this->load->library('upload');
		
		$this->load->helper('haowt');
		$this->_data['img_arr'] = array('jpg', 'jpeg', 'png', 'gif');

		
	}

	public function index() {
		
	}

	
	public function upload_images_json() {
		$config['upload_path'] = FCPATH.$this->_upload_image_dir;
		$config['allowed_types'] = $this->_image_exts;
		$this->upload->initialize($config);
		
		if (!$this->upload->do_upload($fileld = 'imgFile')) {
			log_message('debug', $this->upload->display_errors());
			
			throw_json(array(
				'error' => 1,
				'msg' => $this->upload->display_errors(),
			));
		} else {
			$upload_data = $this->upload->data();
				
			throw_json(array(
				'error' => 0, 
				'url' => base_url($this->_upload_image_dir.$upload_data['file_name']),
			));
		}
	}
	
	public function upload_slide_json() {
		$config['upload_path'] = FCPATH.'data/slide/';
		$config['allowed_types'] = $this->_image_exts;
		$this->upload->initialize($config);
	
		if (!$this->upload->do_upload($fileld = 'imgFile')) {
			//log_message('debug', $this->upload->display_errors());
				
			throw_json(array(
			'error' => 1,
			'msg' => $this->upload->display_errors(),
			));
		} else {
			$upload_data = $this->upload->data();
	
			throw_json(array(
			'error' => 0,
			'url' => base_url('data/slide/'.$upload_data['file_name']),
			'path' => 'data/slide/'.$upload_data['file_name'],
			));
		}
	}




	
}

/* End of file upload.php */
/* Location: ./application/controllers/upload.php */